package cn.dubito.android_linearing;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SecondActivity extends AppCompatActivity {

    /**
     * 重写返回back按钮销毁方法
     */
    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("data_return","Hello MenuActivity");
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Button btn = findViewById(R.id.btn2);

        /**
         * 点击主动销毁
         */
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("data_return","Hello MenuActivity");
                setResult(RESULT_OK,intent);
                finish();
            }
        });





//        Intent intent = getIntent();
        // 获取传递的数据
//        String data = intent.getStringExtra("extra_data");
//        Log.d("SecondActivity", data);


    }
}
